package com.bw.gmall.realtime.common.util;

import org.apache.flink.table.api.Table;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.Reader;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

public class IkUtil {

    /**
     * 分词
     * @param s
     * @return
     */
    public static Set<String> split(String s){
        Set<String> words = new HashSet<>();
        Reader reader = new StringReader(s);
        IKSegmenter segmenter = new IKSegmenter(reader, true);
        try {
            Lexeme next = segmenter.next();
            while ( next != null){
                words.add(next.getLexemeText());
                next = segmenter.next();
            }
        }catch ( Exception e){

        }
        return words;

    }
}
